package diva.pap.affiliate;

import static diva.lib.lang.Lang.set;

import android.app.Activity;
import diva.android_library.rpc.Response;
import diva.pap.R;
import diva.pap.SellNotificationPresenter;
import diva.pap.SellNotificationRequest;

public class AffiliateSellNotificationPresenter extends SellNotificationPresenter {

  public AffiliateSellNotificationPresenter(Activity activity) {
    super(activity);
  }

  @Override
  protected SellNotificationRequest<?> createNotificationRequest() {
    return new AffiliateSellNotificationRequest(new Response<AffiliateSellNotificationRequest>() {
      public void onReuestDone(AffiliateSellNotificationRequest request) {
        onNotificationRequestDone(request);
      }

      public void onReuestFailed() {}
    });
  }

  private void onNotificationRequestDone(AffiliateSellNotificationRequest request) {
    super.onNotificationRequestDone(request);
    for (AffiliateSellNotificationData data : request.getSells()) {
      String title = getString(R.string.notification_sell_content_title);
      if (set(data.getCommission())) title += " - " + data.getCommission();
      showSellNotification(title, data.getCampaignName());
    }
  }

}
